/* ADMIN	->	1
 * VENTAS	->	2
 * RH		->	3
 * RS		->	4
 * EMPLEADO	-> 	5
 */
function onloadMaster() {
	/***************/
	var activeSession = $("#sessionActive").val();
	var userName = $("#userNameSession").val();
	if(activeSession=="true") {
		var typeUser = $("#userTypeSession").val();
		if(typeUser=="1") {
			$("#content").load("Admin.jsp");
		} else if(typeUser=="2") {
			$("#content").load("Ventas.jsp");
		} else if(typeUser=="3") {
			$("#content").load("RH.jsp");
		} else if(typeUser=="4") {
			$("#content").load("Reclutamiento.jsp");
		} else if(typeUser=="5") {
			$("#content").load("Welcome.jsp");
		}
		$("#userin").text("Bienvenido: "+userName);
		loadMenu(typeUser);
	} else {
		$("#content").load("Login.jsp");
	}
	$("#principal").corner();
	
	/** TEsting **
	$("#content").load("Admin.jsp");
	/***/
}

function loadMenu(type) {
	if(type=="1") {
		var tbl = "<table  cellspacing='0'>" + 
						"<tr>" +
							"<td id='ventas' onmousemove='mouseover(this)' onmouseout='mosueout(this)' onclick='selectComponent(this)'>&nbsp;&nbsp;&nbsp;&nbsp;Ventas&nbsp;</td>" +
							"<td>|</td>" +
							"<td id='reclutamiento' onmousemove='mouseover(this)' onmouseout='mosueout(this)' onclick='selectComponent(this)'>&nbsp;&nbsp;&nbsp;&nbsp;Reclutamiento&nbsp;</td>" +
							"<td>|</td>" +
							"<td id='rh' onmousemove='mouseover(this)' onmouseout='mosueout(this)' onclick='selectComponent(this)'>&nbsp;&nbsp;&nbsp;&nbsp;RH&nbsp;</td>" +
							"<td>|</td>" +
							"<td id='admin' onmousemove='mouseover(this)' onmouseout='mosueout(this)' onclick='selectComponent(this)'>&nbsp;&nbsp;&nbsp;&nbsp;Administraci\u00f3n&nbsp;</td>" +
						"</tr>" +
					"</table>";
		$("#tblMenu").html(tbl);
	} else if(type=="2") {
		var tbl = "<table style='position:relative;top: 0px;left:105px;' cellspacing='0'>" + 
							"<tr id='trMenu'>" +
							"<td id='ventas' onmousemove='mouseover(this)' onmouseout='mosueout(this)' onclick='selectComponent(this)'>&nbsp;&nbsp;&nbsp;&nbsp;Ventas&nbsp;</td>" +
						"</tr>" +
					"</table>";
		$("#tblMenu").html(tbl);
	} else if (type=="3") {
		var tbl = 	"<table style='position:relative;top: 0px;left:55px;' cellspacing='0'>" + 
							"<tr id='trMenu'>" +
							"<td id='rh' onmousemove='mouseover(this)' onmouseout='mosueout(this)' onclick='selectComponent(this)'>&nbsp;&nbsp;&nbsp;&nbsp;Recursos Humanos&nbsp;</td>" +
						"</tr>" +
					"</table>";
		$("#tblMenu").html(tbl);
	} else if (type=="4") {
		var tbl =	"<table style='position:relative;top: 0px;left:65px;' cellspacing='0'>" + 
							"<tr id='trMenu'>" +
							"<td id='reclutamiento' onmousemove='mouseover(this)' onmouseout='mosueout(this)' onclick='selectComponent(this)'>&nbsp;&nbsp;&nbsp;&nbsp;Reclutamiento&nbsp;</td>" +
						"</tr>" +
					"</table>";
		$("#tblMenu").html(tbl);
	}
}
function mouseover(component) {
	component.style.backgroundColor = "#969d93";
	component.style.color = "#FFF";
}

function mosueout(component) {
	if(component.id!=$("#menuSelected").val()) {
			component.style.backgroundColor = "#eaeaea";
			component.style.color = "#7f857d";
	}
}

function selectComponent(component) {
	var mSelected = document.getElementById("menuSelected").value;
	if(mSelected=="") {
		$("#menuSelected").val(component.id);
		component.style.backgroundColor = "#969d93";
		component.style.color = "#FFF";
	} else
		if(mSelected!=component.id) {
			mouseover(component);
			$("#menuSelected").val(component.id);
			mosueout(document.getElementById(mSelected));
		}
	
	showPage(component);
}

function showPage(component) {
	var pageToShow = "";
	if(component.id=="admin") {pageToShow = "Admin.jsp";}
	else if(component.id=="ventas") {pageToShow = "Ventas.jsp";}
	else if(component.id=="reclutamiento") {pageToShow = "Reclutamiento.jsp";}
	else if(component.id=="rh") {pageToShow = "RH.jsp";}
	else if(component.id=="catalogo") {pageToShow = "Catalogos.jsp";}
	else if(component.id=="config") {pageToShow = "Config.jsp";}
	
	$("#content").load(pageToShow);
}